<template>
  <div>
    <!-- 头像资料区域 -->
    <div class="profile-box">
      <!-- vant里组件名叫什么，必然有一个类名也叫什么  -->
      <!-- 插件只能帮你转style里的单位，行内样式转不了 -->
      <van-image fit="cover" round :src="userInfo.photo" />
      <div class="info-box">
        <h3 class="name">{{ userInfo.name }}</h3>
        <span class="birthday">{{ userInfo.birthday }}</span>
      </div>
    </div>
    <!-- 快捷入口 -->
    <van-grid :border="false" :column-num="3">
      <van-grid-item
        style="color: #3296fa;"
        icon="newspaper-o"
        text="我的作品"
      />
      <van-grid-item style="color: #f00;" icon="star-o" text="我的收藏" />
      <van-grid-item style="color:orange;" icon="tosend" text="阅读历史" />
    </van-grid>
    <!-- 四个cell -->
    <van-cell-group>
        <van-cell to="/mine/edit" icon="edit" title="编辑资料" is-link />
        <van-cell to="/mine/chat" icon="chat-o" title="小智同学" is-link />
        <van-cell icon="setting-o" title="系统设置" is-link />
        <van-cell @click="$store.dispatch('user/logout')" icon="info-o" title="退出登录" is-link />
    </van-cell-group>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'MyMine',
  computed: {
    ...mapState('user', ['userInfo'])
  },
  async created () {
    // 封装到vuex里了
    this.$store.dispatch('user/reqUserInfo')
  }
}
</script>

<style lang="less" scoped>
.profile-box {
  @color: #3296fa;
  height: 140px;
  background-color: @color;
  display: flex;
  align-items: center;

  .van-image {
    margin: 0 20px;
    width: 120px;
    height: 120px;
  }
  .info-box {
    .name {
      font-size: 20px;
      color: #fff;
      margin-bottom: 10px;
    }
    .birthday {
      background-color: #fff;
      color: @color;
      padding: 3px 2px;
    }
  }
}
</style>
